#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > geoopt_delintsad.info <<'%EOF%'
   geoopt_delintsad
   ----------------
   Molecule:         C2H6
   Wave Function:    SCF / STO-3G
   Test Purpose:     Saddle point optimization in delocalized internal
                     coordinates. The initial Hessian is calculated, then
                     updated using the Rank one (MS) formula. The step is
                     controlled with the partitioned rational function
                     method and Baker's convergence criteria are used
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > geoopt_delintsad.mol <<'%EOF%'
BASIS
STO-3G
First order saddle point optimization in delocalized internal coordinates
The initial molecular Hessian is calculated
Atomtypes=2
Charge=6.0 Atoms=2
C     0.0000000000        0.0000000000        1.4597876282             *
C     0.0000000000        0.0000000000       -1.4597876282             *
Charge=1.0 Atoms=6
H     1.6808445513        0.9704360937        2.1445545504             *
H    -1.6808445513        0.9704360937        2.1445545504             *
H     0.0000000000       -1.9408721894        2.1445545504             *
H    -1.9608445513       -0.4204360937       -2.1445545504             *
H     1.2008445513       -1.4004360937       -2.1445545504             *
H     0.4600000000        1.8308721894       -2.1445545504             *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > geoopt_delintsad.dal <<'%EOF%'
**DALTON INPUT
.OPTIMIZE
*OPTIMIZE
.DELINT
.RF
.INITHE
.RANKON
.SADDLE
.BAKER
**WAVE FUNCTION
.HF
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >geoopt_delintsad.check
cat >>geoopt_delintsad.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

#
# March 2012: disabled some checkes  because initial geometry changed. Not worth it to update all tests. --hjaaj
#

# Geometry optimization
CRIT1=`$GREP "Saddle point optimization has been requested\." $log | wc -l`
CRIT2=`$GREP "1st order method with rank one update will be used\." $log | wc -l`
CRIT3=`$GREP "Optimization will be performed in delocalized internal coordinates\." $log | wc -l`
CRIT4=`$GREP "Initial Hessian will be calculated\." $log | wc -l`
CRIT5=`$GREP "Partitioned rational function method will be used to control step\." $log | wc -l`
CRIT6=`$GREP "The eigenvector corresponding to the lowest non-zero eigenvalue is chosen" $log | wc -l`
CRIT7=`$GREP "as reaction mode \(default\)\." $log | wc -l`
CRIT8=`$GREP "Baker.s convergence criteria will be used" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[1]=8
ERROR[1]="GEOMETRY OPTIMIZATION NOT SET UP CORRECTLY"

# Basis set
CRIT1=`$GREP "C * 2 * 6\.0000 * 15 * 5 * \[6s3p\|2s1p\]" $log | wc -l`
CRIT2=`$GREP "H * 6 * 1\.0000 * 3 * 1 * \[3s\|1s\]" $log | wc -l`
CRIT3=`$GREP "total\: * 8 * 18\.0000 * 48 * 16" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[2]=3
ERROR[2]="BASIS SET NOT READ CORRECTLY"

# Geometry
#CRIT1=`$GREP "Total number of coordinates\: * 24" $log | wc -l`
#CRIT2=`$GREP "3 * z * 1\.4598223474" $log | wc -l`
#CRIT3=`$GREP "4 * x * (0| )\.0201357029" $log | wc -l`
#CRIT4=`$GREP "6 * z * \-1\.4596834723" $log | wc -l`
#CRIT5=`$GREP "7 * x * 1\.6428197329" $log | wc -l`
#CRIT6=`$GREP "8 * y * 1\.0258944623" $log | wc -l`
#CRIT7=`$GREP "9 * z * 2\.1559360111" $log | wc -l`
#CRIT8=`$GREP "10 * x * \-1\.7169234124" $log | wc -l`
#CRIT9=`$GREP "11 * y * (0| )\.9139003605" $log | wc -l`
#CRIT10=`$GREP "12 * z * 2\.1327640108" $log | wc -l`
#CRIT11=`$GREP "13 * x * (0| )\.0599355947" $log | wc -l`
#CRIT12=`$GREP "14 * y * \-1\.9397948248" $log | wc -l`
#CRIT13=`$GREP "15 * z * 2\.1450189290" $log | wc -l`
#CRIT14=`$GREP "16 * x * \-1\.9208446692" $log | wc -l`
#CRIT15=`$GREP "17 * y * (\-0|\-)\.4855279159" $log | wc -l`
#CRIT16=`$GREP "18 * z * \-2\.1578535369" $log | wc -l`
#CRIT17=`$GREP "19 * x * 1\.2716620058" $log | wc -l`
#CRIT18=`$GREP "20 * y * \-1\.3596527890" $log | wc -l`
#CRIT19=`$GREP "21 * z * \-2\.1358349591" $log | wc -l`
#CRIT20=`$GREP "22 * x * (0| )\.4235983754" $log | wc -l`
#CRIT21=`$GREP "23 * y * 1\.8451807069" $log | wc -l`
#CRIT22=`$GREP "24 * z * \-2\.1416840166" $log | wc -l`
#TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
#		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
#		$CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ \
#		$CRIT19 \+ $CRIT20 \+ $CRIT21 \+ $CRIT22`
#CTRL[3]=22
#CTRL[3]=0
#ERROR[3]="GEOMETRY NOT READ CORRECTLY"

# Initial energy
CRIT1=`$GREP "Final * HF energy\: * \-78\.300809229[01]" $log | wc -l`
TEST[4]=`expr	$CRIT1`
CTRL[4]=1
ERROR[4]="INITIAL ENERGY NOT CORRECT"

# Initial gradient
CRIT1=`$GREP "C * (\-0|\-)\.00119.* * (0| )\.00002.* * (0| )\.00942" $log | wc -l`
CRIT2=`$GREP "C * (0| )\.07332.* * (\-0|\-)\.00365.* * (\-0|\-)\.02252" $log | wc -l`
CRIT3=`$GREP "H * (0| )\.00332.* * (0| )\.00326.* * (\-0|\-)\.00352" $log | wc -l`
CRIT4=`$GREP "H * (\-0|\-)\.00483.* * (0| )\.00129.* * (\-0|\-)\.00329" $log | wc -l`
CRIT5=`$GREP "H * (0| )\.00104.* * (\-0|\-)\.00472.* * (\-0|\-)\.00321" $log | wc -l`
CRIT6=`$GREP "H * (\-0|\-)\.02820.* * (\-0|\-)\.00372.* * (\-0|\-)\.00779" $log | wc -l`
CRIT7=`$GREP "H * (\-0|\-)\.03221.* * (0| )\.02426.* * (0| )\.01976" $log | wc -l`
CRIT8=`$GREP "H * (\-0|\-)\.01124.* * (\-0|\-)\.01674.* * (0| )\.01115" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[5]=8

CRIT1=`$GREP "Norm of gradient * \:  * 0*\.09751" $log | wc -l`
TEST[5]=`expr	$CRIT1 `
CTRL[5]=1

ERROR[5]="INITIAL GRADIENT NOT CORRECT"

# Initial Hessian
CRIT1=`$GREP "C * x * (0| )\.86251[0-9]" $log | wc -l`
CRIT2=`$GREP "C * y * (\-0|\-)\.00096[0-9] * (0| )\.86435[0-9]" $log | wc -l`
CRIT3=`$GREP "C * z * (0| )\.00109[0-9] * (\-0|\-)\.00010[0-9] * (0| )\.70141[0-9]" $log | wc -l`
CRIT4=`$GREP "C * x * (\-0|\-)\.12117[0-9] * (\-0|\-)\.00014[0-9] * (0| )\.00268[0-9] * (0| )\.81622[0-9]" $log | wc -l`
CRIT5=`$GREP "C * y * (0| )\.00352[0-9] * (\-0|\-)\.12458[0-9] * (\-0|\-)\.00024[0-9] * (\-0|\-)\.08695[0-9] * (0| )\.99219[0-9]" $log | wc -l`
CRIT6=`$GREP "C * z * (0| )\.00052[0-9] * (0| )\.00005[0-9] * (\-0|\-)\.31691[0-9] * (\-0|\-)\.06257[0-9] * (0| )\.00548[0-9] * (0| )\.70413[0-9]" $log | wc -l`
CRIT7=`$GREP "H * x * (\-0|\-)\.32284[0-9] * (\-0|\-)\.14906[0-9] * (\-0|\-)\.09926[0-9] * (0| )\.00551[0-9] * (0| )\.00317[0-9] * (0| )\.00312[0-9]" $log | wc -l`
CRIT8=`$GREP "H * y * (\-0|\-)\.15015[0-9] * (\-0|\-)\.17710[0-9] * (\-0|\-)\.06334[0-9] * (0| )\.00294[0-9] * (0| )\.00232[0-9] * (0| )\.00326[0-9]" $log | wc -l`
CRIT9=`$GREP "H * z * (\-0|\-)\.10020[0-9] * (\-0|\-)\.06308[0-9] * (\-0|\-)\.11527[0-9] * (\-0|\-)\.03940[0-9] * (\-0|\-)\.02166[0-9] * (\-0|\-)\.01473[0-9]" $log | wc -l`
CRIT10=`$GREP "H * x * (\-0|\-)\.34570[0-9] * (0| )\.13995[0-9] * (0| )\.10171[0-9] * (0| )\.00564[0-9] * (\-0|\-)\.00300[0-9] * (\-0|\-)\.00467[0-9]" $log | wc -l`
CRIT11=`$GREP "H * y * (0| )\.13876[0-9] * (\-0|\-)\.15772[0-9] * (\-0|\-)\.05264[0-9] * (\-0|\-)\.00306[0-9] * (0| )\.00192[0-9] * (0| )\.00101[0-9]" $log | wc -l`
CRIT12=`$GREP "H * z * (0| )\.10143[0-9] * (\-0|\-)\.05329[0-9] * (\-0|\-)\.11227[0-9] * (0| )\.03821[0-9] * (\-0|\-)\.02385[0-9] * (\-0|\-)\.01394[0-9]" $log | wc -l`
CRIT13=`$GREP "H * x * (\-0|\-)\.08394[0-9] * (0| )\.01100[0-9] * (\-0|\-)\.00463[0-9] * (0| )\.00030[0-9] * (\-0|\-)\.00050[0-9] * (0| )\.00125[0-9]" $log | wc -l`
CRIT14=`$GREP "H * y * (0| )\.00994[0-9] * (\-0|\-)\.41783[0-9] * (0| )\.11629[0-9] * (0| )\.00001[0-9] * (0| )\.00737[0-9] * (\-0|\-)\.00458[0-9]" $log | wc -l`
CRIT15=`$GREP "H * z * (\-0|\-)\.00402[0-9] * (0| )\.11643[0-9] * (\-0|\-)\.11417[0-9] * (0| )\.00076[0-9] * (0| )\.04537[0-9] * (\-0|\-)\.01405[0-9]" $log | wc -l`
CRIT16=`$GREP "H * x * (0| )\.00612[0-9] * (0| )\.00157[0-9] * (0| )\.00405[0-9] * (\-0|\-)\.33890[0-9] * (\-0|\-)\.06143[0-9] * (\-0|\-)\.08462[0-9]" $log | wc -l`
CRIT17=`$GREP "H * y * (0| )\.00154[0-9] * (0| )\.00052[0-9] * (\-0|\-)\.00008[0-9] * (\-0|\-)\.06039[0-9] * (\-0|\-)\.10978[0-9] * (\-0|\-)\.02058[0-9]" $log | wc -l`
CRIT18=`$GREP "H * z * (\-0|\-)\.04218[0-9] * (\-0|\-)\.01388[0-9] * (\-0|\-)\.01408[0-9] * (\-0|\-)\.08741[0-9] * (\-0|\-)\.02201[0-9] * (\-0|\-)\.11288[0-9]" $log | wc -l`
CRIT19=`$GREP "H * x * (0| )\.00439[0-9] * (\-0|\-)\.00410[0-9] * (\-0|\-)\.00302[0-9] * (\-0|\-)\.27524[0-9] * (0| )\.22877[0-9] * (0| )\.11318[0-9]" $log | wc -l`
CRIT20=`$GREP "H * y * (\-0|\-)\.00440[0-9] * (0| )\.00460[0-9] * (0| )\.00456[0-9] * (0| )\.23037[0-9] * (\-0|\-)\.31421[0-9] * (\-0|\-)\.12202[0-9]" $log | wc -l`
CRIT21=`$GREP "H * z * (0| )\.03396[0-9] * (\-0|\-)\.03090[0-9] * (\-0|\-)\.01443[0-9] * (0| )\.11418[0-9] * (\-0|\-)\.12181[0-9] * (\-0|\-)\.11598[0-9]" $log | wc -l`
CRIT22=`$GREP "H * x * (0| )\.00064[0-9] * (0| )\.00173[0-9] * (\-0|\-)\.00262[0-9] * (\-0|\-)\.09236[0-9] * (\-0|\-)\.08357[0-9] * (0| )\.03378[0-9]" $log | wc -l`
CRIT23=`$GREP "H * y * (0| )\.00175[0-9] * (0| )\.00777[0-9] * (\-0|\-)\.00443[0-9] * (\-0|\-)\.08277[0-9] * (\-0|\-)\.45523[0-9] * (0| )\.13738[0-9]" $log | wc -l`
CRIT24=`$GREP "H * z * (0| )\.00939[0-9] * (0| )\.04478[0-9] * (\-0|\-)\.01425[0-9] * (0| )\.03355[0-9] * (0| )\.13874[0-9] * (\-0|\-)\.1156(0|1)[0-9]" $log | wc -l`
CRIT25=`$GREP "H * x * (0| )\.32751[0-9]" $log | wc -l`
CRIT26=`$GREP "H * y * (0| )\.16070[0-9] * (0| )\.17083[0-9]" $log | wc -l`
CRIT27=`$GREP "H * z * (0| )\.10788[0-9] * (0| )\.06640[0-9] * (0| )\.12031[0-9]" $log | wc -l`
CRIT28=`$GREP "H * x * (\-0|\-)\.01856[0-9] * (0| )\.02006[0-9] * (0| )\.01399[0-9] * (0| )\.35178[0-9]" $log | wc -l`
CRIT29=`$GREP "H * y * (\-0|\-)\.02259[0-9] * (0| )\.01367[0-9] * (0| )\.01033[0-9] * (\-0|\-)\.14951[0-9] * (0| )\.15006[0-9]" $log | wc -l`
CRIT30=`$GREP "H * z * (\-0|\-)\.01498[0-9] * (0| )\.00956[0-9] * (0| )\.00625[0-9] * (\-0|\-)\.10767[0-9] * (0| )\.05847[0-9] * (0| )\.11745[0-9]" $log | wc -l`
CRIT31=`$GREP "H * x * (0| )\.00650[0-9] * (\-0|\-)\.03457[0-9] * (0| )\.01562[0-9] * (0| )\.00474[0-9] * (0| )\.03593[0-9] * (\-0|\-)\.01625[0-9]" $log | wc -l`
CRIT32=`$GREP "H * y * (0| )\.00790[0-9] * (\-0|\-)\.01151[0-9] * (0| )\.00818[0-9] * (\-0|\-)\.00682[0-9] * (\-0|\-)\.00942[0-9] * (0| )\.00698[0-9]" $log | wc -l`
CRIT33=`$GREP "H * z * (0| )\.00203[0-9] * (\-0|\-)\.01783[0-9] * (0| )\.00640[0-9] * (\-0|\-)\.00078[0-9] * (\-0|\-)\.01730[0-9] * (0| )\.00613[0-9]" $log | wc -l`
CRIT34=`$GREP "H * x * (0| )\.00092[0-9] * (0| )\.00017[0-9] * (0| )\.00178[0-9] * (0| )\.00144[0-9] * (0| )\.00026[0-9] * (0| )\.00050[0-9]" $log | wc -l`
CRIT35=`$GREP "H * y * (\-0|\-)\.00017[0-9] * (0| )\.00094[0-9] * (\-0|\-)\.00015[0-9] * (\-0|\-)\.00048[0-9] * (0| )\.00035[0-9] * (\-0|\-)\.00001[0-9]" $log | wc -l`
CRIT36=`$GREP "H * z * (0| )\.00121[0-9] * (0| )\.00145[0-9] * (\-0|\-)\.00813[0-9] * (\-0|\-)\.00052[0-9] * (0| )\.00016[0-9] * (0| )\.00337[0-9]" $log | wc -l`
CRIT37=`$GREP "H * x * (0| )\.00027[0-9] * (0| )\.00004[0-9] * (0| )\.00027[0-9] * (0| )\.00073[0-9] * (0| )\.00032[0-9] * (\-0|\-)\.00083[0-9]" $log | wc -l`
CRIT38=`$GREP "H * y * (\-0|\-)\.00015[0-9] * (\-0|\-)\.00015[0-9] * (0| )\.00036[0-9] * (0| )\.00007[0-9] * (0| )\.00088[0-9] * (0| )\.00203[0-9]" $log | wc -l`
CRIT39=`$GREP "H * z * (\-0|\-)\.00026[0-9] * (0| )\.00037[0-9] * (0| )\.00133[0-9] * (\-0|\-)\.00185[0-9] * (0| )\.00036[0-9] * (\-0|\-)\.00836[0-9]" $log | wc -l`
CRIT40=`$GREP "H * x * (0| )\.00067[0-9] * (0| )\.00081[0-9] * (0| )\.00004[0-9] * (\-0|\-)\.00007[0-9] * (\-0|\-)\.00011[0-9] * (\-0|\-)\.00039[0-9]" $log | wc -l`
CRIT41=`$GREP "H * y * (0| )\.00020[0-9] * (0| )\.00100[0-9] * (\-0|\-)\.00038[0-9] * (\-0|\-)\.00026[0-9] * (0| )\.00026[0-9] * (0| )\.00010[0-9]" $log | wc -l`
CRIT42=`$GREP "H * z * (0| )\.00025[0-9] * (0| )\.00012[0-9] * (0| )\.00385[0-9] * (\-0|\-)\.00019[0-9] * (\-0|\-)\.00039[0-9] * (0| )\.00136[0-9]" $log | wc -l`
CRIT43=`$GREP "H * x * (0| )\.07086[0-9]" $log | wc -l`
CRIT44=`$GREP "H * y * (\-0|\-)\.01121[0-9] * (0| )\.42928[0-9]" $log | wc -l`
CRIT45=`$GREP "H * z * (0| )\.00306[0-9] * (\-0|\-)\.12473[0-9] * (0| )\.11893[0-9]" $log | wc -l`
CRIT46=`$GREP "H * x * (0| )\.00004[0-9] * (0| )\.00023[0-9] * (0| )\.00005[0-9] * (0| )\.35335[0-9]" $log | wc -l`
CRIT47=`$GREP "H * y * (0| )\.00020[0-9] * (0| )\.00014[0-9] * (\-0|\-)\.00038[0-9] * (0| )\.06883[0-9] * (0| )\.09936[0-9]" $log | wc -l`
CRIT48=`$GREP "H * z * (0| )\.00042[0-9] * (0| )\.00005[0-9] * (0| )\.00131[0-9] * (0| )\.09396[0-9] * (0| )\.02479[0-9] * (0| )\.11759[0-9]" $log | wc -l`
CRIT49=`$GREP "H * x * (0| )\.00046[0-9] * (\-0|\-)\.00010[0-9] * (\-0|\-)\.00026[0-9] * (\-0|\-)\.01829[0-9] * (0| )\.03065[0-9] * (0| )\.01713[0-9]" $log | wc -l`
CRIT50=`$GREP "H * y * (\-0|\-)\.00070[0-9] * (0| )\.00128[0-9] * (0| )\.00032[0-9] * (\-0|\-)\.01381[0-9] * (0| )\.01187[0-9] * (0| )\.00602[0-9]" $log | wc -l`
CRIT51=`$GREP "H * z * (\-0|\-)\.00006[0-9] * (\-0|\-)\.00037[0-9] * (0| )\.00379[0-9] * (\-0|\-)\.01182[0-9] * (0| )\.01326[0-9] * (0| )\.00643[0-9]" $log | wc -l`
CRIT52=`$GREP "H * x * (0| )\.00101[0-9] * (0| )\.00005[0-9] * (\-0|\-)\.00084[0-9] * (\-0|\-)\.00468[0-9] * (\-0|\-)\.04017[0-9] * (0| )\.01739[0-9]" $log | wc -l`
CRIT53=`$GREP "H * y * (\-0|\-)\.00013[0-9] * (0| )\.00070[0-9] * (\-0|\-)\.00188[0-9] * (0| )\.00417[0-9] * (\-0|\-)\.00340[0-9] * (0| )\.00340[0-9]" $log | wc -l`
CRIT54=`$GREP "H * z * (0| )\.00059[0-9] * (\-0|\-)\.00183[0-9] * (\-0|\-)\.00835[0-9] * (\-0|\-)\.00390[0-9] * (\-0|\-)\.01682[0-9] * (0| )\.00637[0-9]" $log | wc -l`
CRIT55=`$GREP "H * x * (0| )\.27541[0-9]" $log | wc -l`
CRIT56=`$GREP "H * y * (\-0|\-)\.24072[0-9] * (0| )\.30987[0-9]" $log | wc -l`
CRIT57=`$GREP "H * z * (\-0|\-)\.11923[0-9] * (0| )\.12684[0-9] * (0| )\.12046[0-9]" $log | wc -l`
CRIT58=`$GREP "H * x * (0| )\.01225[0-9] * (0| )\.02935[0-9] * (\-0|\-)\.01490[0-9] * (0| )\.08252[0-9]" $log | wc -l`
CRIT59=`$GREP "H * y * (\-0|\-)\.01486[0-9] * (\-0|\-)\.0141[45][0-9] * (0| )\.01225[0-9] * (0| )\.09191[0-9] * (0| )\.46304[0-9]" $log | wc -l`
CRIT60=`$GREP "H * z * (\-0|\-)\.00724[0-9] * (\-0|\-)\.01813[0-9] * (0| )\.00676[0-9] * (\-0|\-)\.03244[0-9] * (\-0|\-)\.14645[0-9] * (0| )\.11986[0-9]" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ \
		$CRIT19 \+ $CRIT20 \+ $CRIT21 \+ $CRIT22 \+ $CRIT23 \+ $CRIT24 \+ \
		$CRIT25 \+ $CRIT26 \+ $CRIT27 \+ $CRIT28 \+ $CRIT29 \+ $CRIT30 \+ \
		$CRIT31 \+ $CRIT32 \+ $CRIT33 \+ $CRIT34 \+ $CRIT35 \+ $CRIT36 \+ \
		$CRIT37 \+ $CRIT38 \+ $CRIT39 \+ $CRIT40 \+ $CRIT41 \+ $CRIT42 \+ \
		$CRIT43 \+ $CRIT44 \+ $CRIT45 \+ $CRIT46 \+ $CRIT47 \+ $CRIT48 \+ \
		$CRIT49 \+ $CRIT50 \+ $CRIT51 \+ $CRIT52 \+ $CRIT53 \+ $CRIT54 \+ \
		$CRIT55 \+ $CRIT56 \+ $CRIT57 \+ $CRIT58 \+ $CRIT59 \+ $CRIT60`
CTRL[6]=60
CTRL[6]=0
ERROR[6]="INITIAL HESSIAN NOT CORRECT"

# Initial step
CRIT1=`$GREP "C * (\-0|\-)\.01477.* * (\-0|\-)\.00031.* * 1\.45548" $log | wc -l`
CRIT2=`$GREP "C * (\-0|\-)\.0345[4-5].* * (\-0|\-)\.00(189|190).* * \-1\.45750" $log | wc -l`
CRIT3=`$GREP "H * 1\.56026.* * 1\.10220.* * 2\.1723[0-1]" $log | wc -l`
CRIT4=`$GREP "H * \-1\.7494[4-5].* * 0*\.8084[1-2].* * 2\.1950[6-9]" $log | wc -l`
CRIT5=`$GREP "H * 0*\.15979.* * \-1\.9109[5-7].* * 2\.1829[1-3]" $log | wc -l`
CRIT6=`$GREP "H * \-1\.91719.* * \-0*\.38188.* * \-2\.166[0-1]" $log | wc -l`
CRIT7=`$GREP "H * 1\.2206[4-5].* * \-1\.43410.* * \-2\.1944[45]" $log | wc -l`
CRIT8=`$GREP "H * 0*\.55564.* * 1\.81854.* * \-2\.1892[5-6]" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[7]=8
CTRL[7]=0
ERROR[7]="INITIAL STEP NOT CORRECT"

# Second iteration
CRIT1=`$GREP "Energy at this geometry is * \: * \-78\.30458[0-9]" $log | wc -l`
CRIT2=`$GREP "Norm of gradient * \: * (0| )\.00828[0-9]" $log | wc -l`
CRIT3=`$GREP "Norm of step * \: * (0| )\.3697[6-7][0-9]" $log | wc -l`
TEST[8]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[8]=3
ERROR[8]="SECOND ITERATION NOT CORRECT"

# Third iteration
CRIT1=`$GREP "Energy at this geometry is * \: * \-78\.30378" $log | wc -l`
CRIT2=`$GREP "Norm of gradient * \: * (0| )\.0054" $log | wc -l`
CRIT3=`$GREP "Norm of step * \: * (0| )\.3699" $log | wc -l`
TEST[9]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[9]=3
ERROR[9]="THIRD ITERATION NOT CORRECT"

# Final geometry
CRIT1=`$GREP "C * (\-0|\-)\.01544....[0-9] * (\-0|\-)\.00012....[0-9] * 1\.46245....[0-9]" $log | wc -l`
CRIT2=`$GREP "C * (\-0|\-)\.03946....[0-9] * (0| )\.00012....[0-9] * \-1\.46283....[0-9]" $log | wc -l`
CRIT3=`$GREP "H * 1\.13454....[0-9] * 1\.53334....[0-9] * 2\.19276....[0-9]" $log | wc -l`
CRIT4=`$GREP "H * \-1\.90936.* * 0*\.2237[23].* * 2\.2176[4-5]" $log | wc -l`
CRIT5=`$GREP "H * 0*\.7467[01].* * \-1\.75765.* * 2\.1956[4-5]" $log | wc -l`
CRIT6=`$GREP "H * \-1\.9455[0-1]....[0-9] * 0*\.22423....[0-9] * \-2\.18680....[0-9]" $log | wc -l`
CRIT7=`$GREP "H * (0| )\.71043....[0-9] * \-1\.7573[0-1]....[0-9] * \-2\.2087[3-4]....[0-9]" $log | wc -l`
CRIT8=`$GREP "H * 1\.0984[7-8]....[0-9] * 1\.53365....[0-9] * \-2\.2116[4-5]....[0-9]" $log | wc -l`
TEST[10]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[10]=20
CTRL[10]=0
ERROR[10]="FINAL GEOMETRY NOT CORRECT"

# Geometry converged
CRIT1=`$GREP "Geometry converged in * 9( |  )iterations\!" $log | wc -l`
CRIT2=`$GREP "Energy at final geometry is * \: * \-78\.30160[0-9] a\.u\." $log | wc -l`
CRIT3=`$GREP "Energy change during optimization \: * (\-0|\-)\.00079[0-9] a\.u\." $log | wc -l`
TEST[11]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[11]=3
ERROR[11]="GEOMETRY OPTIMIZATION NOT CONVERGED CORRECTLY"

PASSED=1
for i in 1 2 4 5 6 7 8 9 10 11
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} : ${TEST[i]} .lt. ${CTRL[i]} ; "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
